package com.demo.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.demo.mapper.CanvasResMapper;
import com.demo.model.CanvasRes;
import com.demo.service.CanvasResService;
import com.demo.utils.UUIDUtis;
@Service
public class CanvasResServiceImpl implements CanvasResService {
	@Autowired
	private CanvasResMapper canvasResMapper;
	
	@Override
	public List<CanvasRes> findByCanvasId(String canvasId) {
		return canvasResMapper.findByCanvasId(canvasId);
	}

	@Override
	public void saveByJson(String json) {
		List<CanvasRes> list = JSONArray.parseArray(json, CanvasRes.class);
		if(list != null && list.size() > 0){
			//删除原来的画布资源
			canvasResMapper.deleteByCanvasId(list.get(0).getCanvasId());
			//将新的资源入库
			for (CanvasRes canvasRes : list) {
				canvasRes.setId(UUIDUtis.get());
				canvasResMapper.insert(canvasRes);
			}
		}
	}

}
